#!/bin/bash
echo $PWD
# 编译
gcc touch-right.c -o touch-right -l pthread

# 安装
sudo cp -f touch-right /usr/bin
sudo chmod +x /usr/bin/touch-right

cat > $PWD/touch-right.service << EOF
[Unit]
Description=TouchRightService

[Service]
ExecStart=sudo /usr/bin/touch-right

[Install]
WantedBy=multi-user.target
EOF

# 默认的触屏信息
cat << EOF | su root
123456
cat > /var/touch_infos << EOE
WaveShare WaveShare
Waveshare
WaveShare WS170120
STMicroelectronics 7H Custom Human interface
ILITEK ILITEK-TP
EOE
EOF

sync

if [ -e /etc/systemd/system/touch-right.service ]; then
    sudo systemctl disable touch-right.service
    sudo systemctl stop touch-right.service
fi
sudo cp -rf $PWD/touch-right.service /usr/bin

rm $PWD/touch-right.service
rm $PWD/touch-right

sudo systemctl enable /usr/bin/touch-right.service
sudo systemctl daemon-reload
sudo systemctl start touch-right.service

